﻿@page "/system_manager/resource"
@using Gardener.Application.Dtos
@inherits TreeTableBase<ResourceDto, Guid, ResourceEdit, EditInput<Guid>, EditOutput<Guid>>
<div>
    <PageContainer Title="">
        <Breadcrumb>
            <Breadcrumb>
                <BreadcrumbItem>系统管理</BreadcrumbItem>
                <BreadcrumbItem>资源管理</BreadcrumbItem>
            </Breadcrumb>
        </Breadcrumb>
        <ChildContent>
            <Table TItem="ResourceDto"
                   DataSource="@_dtos"
                   OnChange="@onChange"
                   Loading="@_tableIsLoading"
                   TreeChildren="item=>item.Children"
                   @bind-SelectedRows="_selectedRows"
                   HidePagination="true"
                   IndentSize="25"
                   Context="model">
                <TitleTemplate>
                    <Row>
                        <AntDesign.Col Span="8">
                            <ResourceAuthorize ResourceKey="system_manager_resource_delete_selected">
                                <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnDeletesClick">
                                    删除选中
                                </Button>
                            </ResourceAuthorize>
                        </AntDesign.Col>
                        <AntDesign.Col Span="16" Style="text-align:right">
                            <Space>
                                <ResourceAuthorize ResourceKey="system_manager_resource_add">
                                    <SpaceItem>
                                        <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnAddClick">
                                            添加
                                        </Button>
                                    </SpaceItem>
                                </ResourceAuthorize>
                                <ResourceAuthorize ResourceKey="system_manager_resource_refresh">
                                    <SpaceItem>
                                        <Button Type="@ButtonType.Primary" Icon="reload" OnClick="OnReLoadTable">
                                            刷新
                                        </Button>
                                    </SpaceItem>
                                </ResourceAuthorize>
                                <ResourceAuthorize ResourceKey="system_manager_resource_download_seed_data">
                                    <SpaceItem>
                                        <Button Type="@ButtonType.Primary" Icon="download" OnClick="OnDownloadClick">
                                            种子数据
                                        </Button>
                                    </SpaceItem>
                                </ResourceAuthorize>
                            </Space>
                        </AntDesign.Col>
                    </Row>
                </TitleTemplate>
                <RowTemplate>
                    <Selection CheckStrictly Width="5%" />
                    <Column @bind-Field="@model.Name" Width="20%">
                        <span>
                            @if (!string.IsNullOrEmpty(model.Icon))
                            {
                                <Icon Type="@model.Icon"></Icon>
                            }@model.Name
                        </span>
                    </Column>

                    @*<Column @bind-Field="@model.Key" Width="10%" />
                        <Column @bind-Field="@model.Path" Width="10%"/>*@
                    <Column @bind-Field="@model.Type" Width="5%">
                        <TagRandomColor Text="@(EnumExtension.GetEnumDescription(model.Type))"></TagRandomColor>
                    </Column>
                    <Column @bind-Field="@model.Order" Width="5%" />
                    <Column @bind-Field="@model.IsLocked" Width="10%">
                        <ResourceAuthorize ResourceKey="system_manager_resource_lock">
                            <Authorized>
                                <Switch @bind-Value="@model.IsLocked" OnChange="e=>OnChangeIsLocked(model,e)"></Switch>
                            </Authorized>
                            <NotAuthorized>
                                <TagYesNo Yes="model.IsLocked"></TagYesNo>
                            </NotAuthorized>
                        </ResourceAuthorize>
                    </Column>
                    <Column @bind-Field="@model.CreatedTime" Width="10%" Format="@ClientConstant.DateTimeFormat" />
                    @*<Column @bind-Field="@model.Remark" />*@
                    <ActionColumn Width="10%">
                        <Space>
                            <ResourceAuthorize ResourceKey="system_manager_resource_add_children">
                                <SpaceItem>
                                    <Tooltip Title="@("添加子项")" ArrowPointAtCenter="true">
                                        <Button Icon="subnode" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnAddChildrenClick(model)"></Button>
                                    </Tooltip>
                                </SpaceItem>
                            </ResourceAuthorize>
                            @if (!model.Type.Equals(ResourceType.Root))
                            {
                                <ResourceAuthorize ResourceKey="system_manager_resource_edit">
                                    <SpaceItem>
                                        <Tooltip Title="@("编辑")" ArrowPointAtCenter="true">
                                            <Button Icon="edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnEditClick(model)"></Button>
                                        </Tooltip>
                                    </SpaceItem>
                                </ResourceAuthorize>

                                <ResourceAuthorize ResourceKey="system_manager_resource_show_function">
                                    <SpaceItem>
                                        <Tooltip Title="@("关联接口")" ArrowPointAtCenter="true">
                                            <Button Icon="api" Type="@ButtonType.Primary" OnClick="()=>OnShowFunctionClick(model)"></Button>
                                        </Tooltip>
                                    </SpaceItem>
                                </ResourceAuthorize>
                                <ResourceAuthorize ResourceKey="system_manager_resource_delete">
                                    <SpaceItem>
                                        <Tooltip Title="@("删除(包含子节点)")" ArrowPointAtCenter="true">
                                            <Button Icon="delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnDeleteClick(model)"></Button>
                                        </Tooltip>
                                    </SpaceItem>
                                </ResourceAuthorize>
                            }

                        </Space>
                    </ActionColumn>
                </RowTemplate>
            </Table>
        </ChildContent>
    </PageContainer>
</div>

